<template>
  <h1>注册页面</h1>
  <el-card style="width: 450px;margin: 0 auto;padding: 20px 10px 0 0;">
    <el-form>
      <el-form-item label="用户名">
        <el-input placeholder="请输入用户名" v-model="user.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input placeholder="请输入密码" type="password" v-model="user.password"></el-input>
      </el-form-item>
      <el-form-item label="昵称">
        <el-input placeholder="请输入昵称" v-model="user.nickname"></el-input>
      </el-form-item>
      <el-button type="primary" @click="reg()" style="width: 100%">注册</el-button>
    </el-form>
  </el-card>
</template>

<script setup>
import {ref} from "vue";
import qs from "qs";
import axios from "axios";
import {ElMessage} from "element-plus";
import router from "@/router";

const user=ref({username:'',password:'',nickname:''});
const reg=()=>{
  let data=qs.stringify(user.value);
  console.log(data);
  axios.post('http://localhost:8080/v1/users/reg',data).then((response) => {
        if (response.data.code==2002){
          ElMessage.success('注册成功');
          router.push('/');
        }else {
          ElMessage.error(response.data.msg)
        }
      });
}
</script>

<style scoped>

</style>